<?php

//	Author: 	Aris Michail
//	Email:		std03055@di.uoa.gr
//	Purpose: 	Get a category for a user

require_once ("../DB/DB.php");
require_once ("../Frameworks/Objects/user.php");
require_once ("../Frameworks/Objects/category.php");

function DB_getCategory($categoryid)
{
    global $conn;

    // The name of the stored procedure
    $sp_name = "usp_getCategory";

    // The return variable
    $retval = -2;

    // Create a new statement
    $stmt = mssql_init($sp_name, $conn);

    // Bind values
    mssql_bind($stmt, "RETVAL", $retval, SQLINT4, true, false, 1);
    mssql_bind($stmt, '@categoryid', $categoryid, SQLINT4, false, false, 1);

    // Execute the statement
    $status = mssql_execute($stmt);
    if ($status)
    {
        $category = new Category();
        $category->SetId($categoryid);
        $row = mssql_fetch_row($status);
        $category->SetId($categoryid);
        $category->SetName($row[1]);
        $category->SetPrivacy($row[2]);
        //			$category->SetDateCreated($row[3]);
        $category->SetOwner($row[4]);
        //			$category->SetApproved($row[5]);
        $category->SetEntitiesCount($row[6]);
        $category->SetEntityIds(DB_getEntityIds($categoryid));
        return $category;
    }
}

?>